package com.wzdigit.wms.basic.util;

import com.baomidou.mybatisplus.annotation.TableField;
import com.wzdigit.wms.basic.annotation.SortField;

import java.lang.reflect.Field;

public class SortUtil {

    public static  String dealSort(String sorting,Class clazz){
        String[] sort =sorting.split(" ");
        try {

            Field field = clazz.getDeclaredField(sort[0]);
            SortField annotation = field.getDeclaredAnnotation(SortField.class);
            String realName = annotation.sqlField();
            String ending = sort[1].substring(0, sort[1].indexOf("ending"));
            String lastSort = realName +" "+ ending;
            return  lastSort;
        } catch (Exception e) {
            //有异常返回空先 排序不影响使用
            return  null;
        }
    }

}
